﻿using System;
using System.Threading.Tasks;
using GMS.IServices;
using GMS.Models.Dto;
using Microsoft.AspNetCore.Mvc;

namespace GMS.API.Controllers
{
    [ApiController]
    [Route("PowerInfo")]
    public class PowerInfoController : ControllerBase
    {
        private readonly IPowerInfoService _powerInfoService;

        public PowerInfoController(IPowerInfoService powerInfoService)
        {
            _powerInfoService = powerInfoService;
        }

        [HttpPost("added")]
        public async Task<IActionResult> AddPower(PowerInfoDto dto)
        {
            var res = await _powerInfoService.AddedAsync(dto);
            return res > 0
                ? StatusCode(200, new { code = 200, message = "添加权限成功" })
                : BadRequest(new { code = 500, message = "添加权限失败" });
        }

        [HttpGet("keys")]
        public async Task<IActionResult> GetTreeKeys(Guid roleId)
        {
            var res = await _powerInfoService.GetTreeKeysAsync(roleId);
            return StatusCode(200, new { code = 200, message = "添加权限成功", data = res });
        }
    }
}